import java.lang.reflect.Array;
import java.util.Arrays;
import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 86186
 * Date: 2023-10-26
 * Time: 17:00
 */
public class Test {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        int T = in.nextInt();
        for (int i = 0; i < T; i++) {
            int n = in.nextInt(), k = in.nextInt();
            int[] num = new int[2*n];
            for (int j = 0; j < 2 *n; j++) {
                num[j] = in.nextInt();
            }
            for (int z = 0; z < k; z++) {
                int[] tmp = Arrays.copyOf(num, 2 * n);
                int cur1 = n - 1, cur2 = 2 * n - 1, cur = 2 * n - 1, flg = 1;
                while (cur1 >= 0 && cur2 >= 0) {
                    if (flg > 0) {
                        num[cur--] = tmp[cur2--];
                    }else {
                        num[cur--] = tmp[cur1--];
                    }
                    flg *= -1;
                }
                for (int m = 0; m < 2 * n; m++) {
                    System.out.print(num[m]);
                    if (m != 2 *n - 1) {
                        System.out.print(" ");
                    }
                }
                System.out.println();
            }
        }
    }

    public static void main2(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        int n = in.nextInt();
        String op = in.next();
        char[] o = op.toCharArray();
        int flg = 1;
        if (n <= 4) {
            for (int i = 0; i < o.length; i++) {
                if (o[i] == 'U') {
                    if (flg == 1) {
                        flg = n;
                    }else {
                        flg--;
                    }
                }else {
                    if (flg == n) {
                        flg = 1;
                    }else {
                        flg++;
                    }
                }
            }
            for (int i = 1; i <= n; i++) {
                System.out.print(i);
                if (i != n) {
                    System.out.print(" ");
                }
            }
            System.out.println();
            System.out.println(flg);
        }else {
            int t = 1, d = 4;
            for (int i = 0; i < o.length; i++) {
                if (o[i] == 'U') {
                    if (flg == t) {
                        if (t == 1) {
                            t = n - 3;
                            d = n;
                            flg = n;
                        }else{
                            t = t - 1;
                            d = d - 1;
                            flg = t;
                        }
                    }else {
                        flg--;
                    }
                }else {
                    if (flg == d) {
                        if (d == n) {
                            t = 1;
                            d = 4;
                            flg = 1;
                        }else {
                            t = t + 1;
                            d = d + 1;
                            flg = flg + 1;
                        }
                    }else {
                        flg++;
                    }
                }
            }
            for (int i = t; i <= d; i++) {
                System.out.print(i);
                if (i != d) {
                    System.out.print(" ");
                }
            }
            System.out.println();
            System.out.println(flg);
        }
    }
}
